﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FTchina;

public partial class UI_NewCustomerSelector : System.Web.UI.Page
{

    string NodeList = "  id: {0},pId: 9999999, name: '{1}',tel: 0,count: {2}, times: 1,isParent: {3}";
    protected void Page_Load(object sender, EventArgs e)
    {

    }




    public String getCustomerGroup()
    {
        string tmp = string.Empty;
        DataTable dt = shujuku.GetDataTable("select * from CustomerGroup order by id desc");
        int count = 0;
        string isparent = "false";
        foreach (DataRow dr in dt.Rows)
        {
            count = getCustomerCountByGroupID(dr["id"].ToString());
            isparent = (count > 0) ? "true" : "false";
            tmp += "{" + string.Format(NodeList, dr["id"], dr["GroupName"],count,isparent) + "},";
        }
        count = getCustomerCountByGroupID("0");
        isparent = (count > 0) ? "true" : "false";
        tmp += "{" + string.Format(NodeList, 0, "未分组", count, isparent) + "}";
        return tmp;
    }

    protected int getCustomerCountByGroupID(string GroupID)
    {
        int i = 0;
        string getSql = "select count(id) from CustomerList where CustomerGroupID='" + GroupID + "' order by id desc ";
        int.TryParse(shujuku.GetDataTable(getSql).Rows[0][0].ToString(), out i);
        return i;
    }




}